package com.cauli.manage.operationLog.model.dto;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cauli.manage.operationLog.model.entity.OperationLog;
import com.cauli.model.abstractQuery.AbstractPageQuery;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author Cauli
 * @date 2023-03-28 12:00
 * @description 操作日志添加参数
 */
@Data
@ApiModel(value = "OperationLogQueryDTO", description = "操作日志查询参数")
public class OperationLogQueryDTO extends AbstractPageQuery {
    @ApiModelProperty("操作资源")
    private String source;

    @ApiModelProperty("操作名称")
    private String operation;

    @ApiModelProperty("平台(0管理端 1网盘)")
    private Integer platform;

    @ApiModelProperty("请求类型")
    private String requestMethod;

    @ApiModelProperty("请求URL")
    private String requestUrl;

    @ApiModelProperty("操作结果")
    private String result;

    @Override
    public QueryWrapper toQueryWrapper() {
        return null;
    }

    @Override
    public LambdaQueryWrapper<OperationLog> toLambdaQueryWrapper() {
        LambdaQueryWrapper<OperationLog> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .like(StrUtil.isNotEmpty(source), OperationLog::getSource, source)
                .like(StrUtil.isNotEmpty(operation), OperationLog::getOperation, operation)
                .eq(platform != null, OperationLog::getPlatform, platform)
                .eq(StrUtil.isNotEmpty(requestMethod), OperationLog::getRequestMethod, requestMethod)
                .like(StrUtil.isNotEmpty(requestUrl), OperationLog::getRequestUrl, requestUrl)
                .eq(StrUtil.isNotEmpty(result), OperationLog::getResult, result);
        return lambdaQueryWrapper;
    }
}
